package com.ziyun.erp.modules.production.operate.test;

import com.ziyun.erp.common.e.production.OrderProductionStatusEnum;
import com.ziyun.erp.modules.production.entity.ErpOrderProductionEntity;
import com.ziyun.erp.modules.production.service.ErpOrderProductionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

/**
 * @author guizhao
 * @Title:  待生产 状态
 * @ProjectName ziyun-service-erp
 * @date 2018-09-07 12:27
 */
public class UnProduceStateAction implements  ProductionState{
    /**
     * 日志
     */
    private  static Logger logger = LoggerFactory.getLogger(UnProduceStateAction.class);

    @Autowired
    private ErpOrderProductionService erpOrderProductionService;

    /**
     *  待生产 --> 生产中
     * @param productionContext
     */
    @Override
    public boolean forward(ProductionContext productionContext) {
        ErpOrderProductionEntity erpOrderProductionEntity = productionContext.getErpOrderProductionEntity();
        if(erpOrderProductionEntity.getProductionStatus() != OrderProductionStatusEnum.UN_PRODUCE.toInt()){
            return false;
        }

        Map<String,Object> updateMap = new HashMap<>();
        updateMap.put("productionStatus",OrderProductionStatusEnum.PRODUCING);
        updateMap.put("updateName",erpOrderProductionEntity.getUpdateName());

        erpOrderProductionService.updateByMap(updateMap,erpOrderProductionEntity.getProductionId());

        return true;
    }

    @Override
    public boolean rollback(ProductionContext productionContext) {
        logger.info("返回操作待完成......");
        return false;
    }

    @Override
    public int getState() {
        return OrderProductionStatusEnum.UN_PRODUCE.toInt();
    }
}
